package main

import (
	"context"
	"fmt"
	"log"
	"runtime/debug"
)

// App struct
type App struct {
	ctx context.Context
}

// NewApp creates a new App application struct
func NewApp() *App {
	return &App{}
}

// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) Start(ctx context.Context) {
	a.ctx = ctx
	log.Println("===注意，接下来前端执行onMounted，后端初始化必须在此处完成===")
}

func (a *App) domReady(ctx context.Context) {
	// 统计版本使用情况
	go func() {
		defer func() {
			if err := recover(); err != nil {
				fmt.Println(string(debug.Stack()))
			}
		}()
		// client := resty.New()
		// body := map[string]any{
		// 	"name":     "kafka-ui",
		// 	"version":  "",
		// 	"platform": runtime.GOOS,
		// }
		// _, _ = client.R().SetBody(body).Post("https://www.kafkaui.com/api/v1/usage")
	}()
}

// Greet returns a greeting for the given name
func (a *App) Greet(name string) string {
	return fmt.Sprintf("Hello %s, It's show time!", name)
}
